cmake_minimum_required(VERSION 3.12.4)

#注意事项
#1.工具链文件的路径：确保 toolchain.cmake 的路径是正确的，可以是绝对路径或相对于 CMakeLists.txt 的相对路径。
#2.工具链文件的顺序：工具链文件需要在 project() 命令之前包含，因为 project() 会初始化编译器和相关设置。
#3.硬编码问题：在 CMakeLists.txt 中硬编码工具链文件路径会降低项目的可移植性。推荐通过命令行参数传递工具链文件。
#cmake -DCMAKE_TOOLCHAIN_FILE=../toolchain.cmake ..
include(${CMAKE_SOURCE_DIR}/toolchain.cmake)

project(lvgl_master)

# 添加驱动编译选项
option(ENABLE_DRIVERS "Enable building drivers" OFF)

set(LV_CONF_PATH ${CMAKE_CURRENT_SOURCE_DIR}/lv_conf.h CACHE STRING "Path defined for lv_conf.h")
#set(am335xt3_ROOT_PATH /usr/local/am335xt3 CACHE STRING "Path defined for sdk ,eg tslib")
# 根据ENABLE_DRIVERS选项决定是否编译drivers目录

# 添加 FFmpeg 的头文件路径
include_directories(${CMAKE_INTERNAL_INSTALL_PREFIX}/include)
# 添加 FFmpeg 的库文件路径
link_directories(${CMAKE_INTERNAL_INSTALL_PREFIX}/lib)

if(ENABLE_DRIVERS)
    add_subdirectory(drivers)
endif()

add_subdirectory(lv_drivers)
add_subdirectory(lvgl)
add_subdirectory(thirdpart)
add_subdirectory(apps)
add_subdirectory(servers)

# 强制 lvgl 依赖于 drivers
add_dependencies(lvgl thirdpart)

# 增加pack规则
# 设置版本号
set(CPACK_PACKAGE_VERSION_MAJOR "1")
set(CPACK_PACKAGE_VERSION_MINOR "0")
set(CPACK_PACKAGE_VERSION_PATCH "0")

# 设置包名和描述信息
set(CPACK_PACKAGE_NAME "${PROJECT_NAME}")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "LVGL for AM335x Linux System")
set(CPACK_PACKAGE_VENDOR "LVGL")

# 设置打包的文件和目录
install(DIRECTORY ${CMAKE_BINARY_DIR}/bin
        DESTINATION .
        COMPONENT applications
        FILES_MATCHING PATTERN "*"
        PATTERN ".git" EXCLUDE
)

install(DIRECTORY ${CMAKE_BINARY_DIR}/lib
        DESTINATION .
        COMPONENT libraries
        FILES_MATCHING PATTERN "*.so*" PATTERN "*.a"
)

# 设置打包格式
set(CPACK_GENERATOR "TGZ;DEB")
set(CPACK_SOURCE_GENERATOR "TGZ")

# DEB包特定设置
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "LVGL Team")
set(CPACK_DEBIAN_PACKAGE_SECTION "embedded")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>= 2.19)")

# 包含CPack模块
include(CPack)
